package com.start.form.engine.core.model;

import com.baomidou.mybatisplus.annotation.TableName;
import com.start.avue.AvueBaseFormColumn;
import com.start.common.entity.StartBaseEntity;
import com.start.form.engine.core.entity.StartFormConfig;
import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;

@Data
@TableName("start_form_column")
 @Schema(name="SysFormColumn", description = "动态表列")
public class StartFormColumnModel extends StartBaseEntity {

     @Schema(name="组件类型")
    private String type;

     @Schema(name="数据表名")
    private String tableName;

     @Schema(name="数据表id")
    private String tableId;
     @Schema(name="sql数据类型")
    private String sqlType;
     @Schema(name="数据长度")
    private Integer sqlTypeDataLength;

     @Schema(name="label")
    private String label;

     @Schema(name="数据表列名")
    private String prop;

     @Schema(name="数据列配置")
    private String columnOption;

     @Schema(name="排序序号")
    private Integer sort;


    public static StartFormColumnModel createColumn(StartFormConfig formConfig, String prop, String label, String type, Integer size) {
        StartFormColumnModel column = new StartFormColumnModel();
        column.setTableId(formConfig.getId());
        column.setTableName(formConfig.getTableName());
        column.setProp(prop);
        column.setLabel(label);
        column.setSqlType(type);
        column.setSqlTypeDataLength(size);
        return column;
    }

    public static StartFormColumnModel createColumn(String prop, String label, String type, Integer size) {
        StartFormColumnModel column = new StartFormColumnModel();
        column.setProp(prop);
        column.setLabel(label);
        column.setSqlType(type);
        column.setSqlTypeDataLength(size);
        return column;
    }

    public AvueBaseFormColumn createAvueColumn() {
        AvueBaseFormColumn column = new AvueBaseFormColumn();
        column.setLabel(this.getLabel());
        column.setProp(this.getProp());
        column.setSqlTypeDataLength(this.getSqlTypeDataLength());
        column.setSqlType(this.getSqlType());
        return column;
    }
}
